<link href="Estilos/EstilosPagina.css" rel="stylesheet" type="text/css">
<!--#include file="Librerias/mssql-ds.dll" -->
<%
	'// Recuperar los parametros DondeIr y QueHacer
	DondeIr = request.QueryString("DondeIr")
	if DondeIr = "" then DondeIr = 0
	QueHacer = request.QueryString("QueHacer")
	if QueHacer = "" then QueHacer = 0
	
	'// Comando para Nuevo Registro
	if QueHacer = "cmdNuevo" then
		DondeIr = 1
	end if
	
	'// Comando para Editar Registro
	if QueHacer = "cmdEditar" then
		qFichero = request.QueryString("qFichero")
		if qFichero = "" then qFichero = 0
		DondeIr = 0
		sSQL = ""
		sSQL = sSQL & " SELECT meta_id, proy_id, meta_descripcion, meta_meta"
		sSQL = sSQL & " FROM _Metas"
		sSQL = sSQL & " WHERE (meta_id = "& qFichero &")"
		
		Matriz = MatrixBD(sSQL, 1)
		If VarType(Matriz) = 8  then
			QtyRegistros = -1
		Else
			QtyRegistros = UBound(Matriz,2)	
		End If
		If QtyRegistros <> -1 then
			variable0 =  Matriz(0,0)
			variable1 =  Matriz(1,0)
			variable2 =  Matriz(2,0)
			variable3 =  Matriz(3,0)
			DondeIr = 2
		End If
	End If
	
	'// Comando para Borrar Registro
	if QueHacer = "cmdBorrar" then
		qFichero = request.QueryString("qFichero")
		if qFichero = "" then qFichero = 0
		DondeIr = 3
		variable0 = qFichero
		sSQL = ""
		sSQL = sSQL & " SELECT meta_descripcion FROM _Metas"
		sSQL = sSQL & " WHERE meta_id = "& qFichero &""
		variable1 = RecordBD(sSQL, "meta_descripcion", 1)
	End If
	
	'// Comando para Guardar Nuevo Registro 
	if QueHacer = "cmdNuevoGrabar" then
		DondeIr = 0
		variable1 = Request.Form("variable1")
		variable2 = Request.Form("variable2")
					
		sSQL = ""
		sSQL = sSQL & " INSERT INTO _Metas (proy_id, meta_descripcion, meta_meta)"
		sSQL = sSQL & " VALUES("& Request.Cookies("cookie_granted_proyecto_id") &", '"& variable1 &"', "& variable2 &")"
		Resultado = ExecuteBD(sSQL, 1)
	end if
	
	'// Comando para Guardar Registro Editado 
	If QueHacer = "cmdEditarGrabar" Then
	
		variable0 = Request.Form("variable0")
		variable1 = Request.Form("variable1")
		variable2 = Request.Form("variable2")
		
		If len(variable0) = 0 then  variable0 = "0"
		If len(variable1) = 0 then  variable1 = "0"
		If len(variable2) = 0 then  variable2 = "0"
		
		variable0 = trim(variable0)
		variable1 = trim(variable1)
		variable2 = trim(variable2)
		
		sSQL = ""
		sSQL = sSQL & " UPDATE _Metas"
		sSQL = sSQL & " SET meta_descripcion = '" & variable1 & "',"
		sSQL = sSQL & " meta_meta = " & variable2 & ""
		sSQL = sSQL & " WHERE meta_id = " & variable0 & ""
		Resultado = ExecuteBD(sSQL, 1)
		
		DondeIr = 0
	End If
	
	'// Comando para Guardar Registro Borrado 
	if QueHacer = "cmdBorrarGuardar" then
		DondeIr = 0
		variable0 = request.Form("variable0")
		variable1 = request.Form("variable1")
		sSQL = ""
		sSQL = sSQL & " DELETE FROM _Metas"
		sSQL = sSQL & " WHERE meta_id = "& variable0
		Resultado = ExecuteBD(sSQL, 1)
	end if
%>

<!-- Pagina de inicio -->
<% if DondeIr = 0 then %>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="left">
  <tr>
    <td align="left" valign="middle"><strong>METAS (Listado)</strong></font></td>
  </tr>
  <%
	sSQL = ""
	sSQL = sSQL & " SELECT meta_id, meta_descripcion, meta_meta"
	sSQL = sSQL & " FROM _Metas"
	sSQL = sSQL & " WHERE proy_id = "& Request.Cookies("cookie_granted_proyecto_id")
	Matriz = MatrixBD(sSQL, 1)
	If VarType(Matriz) = 8  then
		QtyRegistros = -1
	Else
		QtyRegistros = UBound(Matriz,2)	
	End If
  %>
  <tr>
    <td align="center">
	<table width="100%" border="0" cellspacing="1" cellpadding="1">
      <tr>
		<td width="20" class="EncabezadoTablaPeq"><a href="SGP.Metas.asp?QueHacer=cmdNuevo"><img src="Iconos/page_add.png" width="16" height="16" border="0" alt="Nuevo"></a></td>
		<td width="20" class="EncabezadoTablaPeq" align="center" title="Editar">E</td>
		<td width="20" class="EncabezadoTablaPeq" align="center" title="Borrar">B</td>
        <td width="60%" class="EncabezadoTablaPeq" align="center">Descripci&oacute;n</td>
        <td width="40%" class="EncabezadoTablaPeq" align="center">Meta</td>
	  </tr>
	  <% for i = 0 to QtyRegistros %>
      <%
	  if i mod 2 = 0 then
	  		bgcolor = "TablaFila1"
	  else
	  		bgcolor = "TablaFila2"
	  end if 
	  %>
	  <tr class="<%=bgcolor%>">
	  	<td>&nbsp;</td>
		<td><a href="SGP.Metas.asp?QueHacer=cmdEditar&qFichero=<%=Matriz(0,i)%>"><img src="Iconos/page_edit.png" width="16" height="16" border="0" alt="Editar"></a></td>
		<td><a href="SGP.Metas.asp?QueHacer=cmdBorrar&qFichero=<%=Matriz(0,i)%>"><img src="Iconos/page_delete.png" width="16" height="16" border="0" alt="Borrar"></a></td>
        
        <td><%=Matriz(1,i)%></td>
        <td><%=Matriz(2,i)%></td>
	  </tr>
	  <% next %>
	</table>
	</td>
  </tr>
</table>
<% end if %>

<!-- Nuevo Registro -->
<% if DondeIr = 1 then %>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="left">
  <tr>
    <td align="left" valign="middle"><strong>METAS (Adicionar)</strong></font></td>
  </tr>
  <tr>
    <td align="center">
	<form action="SGP.Metas.asp?QueHacer=cmdNuevoGrabar" method="post" name="frmNew">
	<table width="100%" border="0" cellspacing="1" cellpadding="1">
	  <tr>
		<td width="40%" class="EncabezadoTablaPeq">Descripci&oacute;n</td>
		<td width="60%"><textarea name="variable1" rows="6" class="TextoTam2"></textarea></td>
	  </tr>
      <tr>
		<td width="40%" class="EncabezadoTablaPeq">Meta</td>
		<td width="60%"><input name="variable2" type="text" class="TextoTam2" value=""></td>
	  </tr>
      <tr>
		<td colspan="2">&nbsp;</td>
      </tr>
	  <tr>
        <td colspan="2" align="center"><input name="Aceptar" value="   Aceptar   " type="submit" class="BotonPeq">&nbsp;<input name="Cancelar" value="   Cancelar   " type="button" class="BotonPeq" onClick="javascript:window.location.href='SGP.Metas.asp'"></td>
      </tr>
	</table>
	</form>
	</td>
  </tr>
</table>
<% end if %>

<!-- Editar Registro -->
<% if DondeIr = 2 then %>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="left">
  <tr>
    <td align="left" valign="middle"><strong>METAS (Editar)</strong></font></td>
  </tr>
  <tr>
    <td align="center">
	<form action="SGP.Metas.asp?QueHacer=cmdEditarGrabar" method="post" name="frmEdit">
    <input name="variable0" type="hidden" value="<%=variable0%>">
	<table width="100%" border="0" cellspacing="1" cellpadding="1">
	  <tr>
		<td width="40%" class="EncabezadoTablaPeq">Descripci&oacute;n</td>
		<td width="60%"><textarea name="variable1" rows="6" class="TextoTam2"><%=variable2%></textarea></td>
	  </tr>
	  <tr>
		<td width="40%" class="EncabezadoTablaPeq">Meta</td>
		<td width="60%"><input name="variable2" type="text" class="TextoTam2" value="<%=variable3%>"></td>
	  </tr>
      <tr>
		<td colspan="2">&nbsp;</td>
      </tr>
	  <tr>
        <td colspan="2" align="center"><input name="Aceptar" value="   Aceptar   " type="submit" class="BotonPeq">&nbsp;<input name="Cancelar" value="   Cancelar   " type="button" class="BotonPeq" onClick="javascript:window.location.href='SGP.Metas.asp'"></td>
      </tr>
	</table>
	</form>
	</td>
  </tr>
</table>
<% end if %>

<!-- Borrar Registro -->
<% if DondeIr = 3 then %>
<table width="300" border="0" cellspacing="0" cellpadding="0" align="left">
  <tr>
    <td align="left" valign="middle"><strong>METAS (Borrar)</strong></font></td>
  </tr>
  <tr>
    <td align="center">
	<form action="SGP.Metas.asp?QueHacer=cmdBorrarGuardar" method="post" name="frmDelete">
	<table width="100%" border="0" cellspacing="1" cellpadding="1">
	  <tr>
		<td width="50%" class="EncabezadoTablaPeq"><input type="hidden" name="variable0" value="<%=variable0%>">Esta seguro de borrar?</td>
		<td width="50%"><input name="variable1" type="text" class="TextoTam2" value="<%=variable1%>" size="50" readonly="readonly"></td>
	  </tr>
	  <tr>
		<td colspan="2">&nbsp;</td>
	  </tr>
	  <tr>
        <td colspan="2" align="center"><input name="Aceptar" value="   Aceptar   " type="submit" class="BotonPeq">&nbsp;<input name="Cancelar" value="   Cancelar   " type="button" class="BotonPeq" onClick="javascript:window.location.href='SGP.Metas.asp'"></td>
      </tr>
	</table>
	</form>
	</td>
  </tr>
</table>
<% end if %>